package evaluacredito.web;

import static org.junit.Assert.fail;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import evaluacredito.dao.PersonaDAOImpl;
import evaluacredito.excepcion.DAOExcepcion;
import evaluacredito.modelo.Persona;

/**
 * Servlet implementation class ListarPersonaServlet
 */
public class ListarPersonaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ListarPersonaServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PersonaDAOImpl personaDAOImpl = new PersonaDAOImpl();
		Collection<Persona> listarPersona = new ArrayList<Persona>();

		try {
			listarPersona=personaDAOImpl.listar();
			System.out.println(listarPersona.size());

		} catch (DAOExcepcion e) {
			fail(e.getMessage());
		}
		
		request.setAttribute("listado", listarPersona);
		request.setAttribute("op", "listado");
		RequestDispatcher rd=request.getRequestDispatcher("/principal.jsp");
		rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

	}
}
